/*
This file was produced by Deep Exploration Plugin: CPP Export filter. 

Copyright (C) 1999-2006 Right Hemisphere
Mail support@righthemisphere.com for support.
Visit http://www.righthemisphere.com/dexp.htm for updates.
*/
#include <windows.h>
#include <GL\gl.h>
#include <GL\glu.h>


struct sample_MATERIAL
{
	GLfloat ambient[3];
	GLfloat diffuse[3];
	GLfloat specular[3];
	GLfloat emission[3];
	GLfloat alpha;
	GLfloat phExp;
	int texture;
};

static sample_MATERIAL materials [1] = {
 {{0.117647f,0.117647f,0.117647f},	{0.752941f,0.752941f,0.752941f},	{0.301177f,0.301177f,0.301177f},	{0.0f,0.0f,0.0f},	1.0f,8.0f,-1} //Explorer Default
};

// 56 Verticies
// 4 Texture Coordinates
// 10 Normals
// 84 Triangles

static BYTE face_indicies[84][9] = {
// Cube
	{3,1,0 ,0,0,0 ,0,1,2 }, {2,3,0 ,0,0,0 ,3,0,2 }, {5,3,2 ,1,2,2 ,0,1,2 },
	{4,5,2 ,3,1,2 ,3,0,2 }, {7,5,4 ,4,4,4 ,0,1,2 }, {6,7,4 ,4,4,4 ,3,0,2 },
	{1,7,6 ,5,6,7 ,0,1,2 }, {0,1,6 ,5,5,7 ,3,0,2 }, {5,7,1 ,1,6,8 ,0,1,2 },
	{3,5,1 ,8,1,8 ,3,0,2 }, {2,0,6 ,9,9,7 ,0,1,2 }, {4,2,6 ,3,9,7 ,3,0,2 }
// Cube4
	, {11,9,8 ,0,0,0 ,0,1,2 }, {10,11,8 ,0,0,0 ,3,0,2 }, {13,11,10 ,1,2,2 ,0,1,2 },
	{12,13,10 ,3,1,2 ,3,0,2 }, {15,13,12 ,4,4,4 ,0,1,2 }, {14,15,12 ,4,4,4 ,3,0,2 },
	{9,15,14 ,5,6,7 ,0,1,2 }, {8,9,14 ,5,5,7 ,3,0,2 }, {13,15,9 ,1,6,8 ,0,1,2 },
	{11,13,9 ,8,1,8 ,3,0,2 }, {10,8,14 ,9,9,7 ,0,1,2 }, {12,10,14 ,3,9,7 ,3,0,2 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42 ,3,1,2 ,3,0,2 }, {47,45,44 ,4,4,4 ,0,1,2 }, {46,47,44 ,4,4,4 ,3,0,2 },
	{41,47,46 ,5,6,7 ,0,1,2 }, {40,41,46 ,5,5,7 ,3,0,2 }, {45,47,41 ,1,6,8 ,0,1,2 },
	{43,45,41 ,8,1,8 ,3,0,2 }, {42,40,46 ,9,9,7 ,0,1,2 }, {44,42,46 ,3,9,7 ,3,0,2 }
// Cube3
	, {51,49,48 ,0,0,0 ,0,1,2 }, {50,51,48 ,0,0,0 ,3,0,2 }, {53,51,50 ,1,2,2 ,0,1,2 },
	{52,53,50 ,3,1,2 ,3,0,2 }, {55,53,52 ,4,4,4 ,0,1,2 }, {54,55,52 ,4,4,4 ,3,0,2 },
	{49,55,54 ,5,6,7 ,0,1,2 }, {48,49,54 ,5,5,7 ,3,0,2 }, {53,55,49 ,1,6,8 ,0,1,2 },
	{51,53,49 ,8,1,8 ,3,0,2 }, {50,48,54 ,9,9,7 ,0,1,2 }, {52,50,54 ,3,9,7 ,3,0,2 }
};
static GLfloat vertices [56][3] = {
{-0.0309473f,-0.5f,0.131328f},{-0.0309473f,-0.5f,0.190151f},{0.0278762f,-0.5f,0.131328f},
{0.0278762f,-0.5f,0.190151f},{0.0278762f,0.5f,0.131328f},{0.0278762f,0.5f,0.190151f},
{-0.0309473f,0.5f,0.131328f},{-0.0309473f,0.5f,0.190151f},{-0.073446f,-0.499031f,0.191179f},
{-0.073446f,-0.499031f,0.220591f},{0.0736129f,-0.499031f,0.191179f},{0.0736129f,-0.499031f,0.220591f},
{0.0736129f,-0.469619f,0.191179f},{0.0736129f,-0.469619f,0.220591f},{-0.073446f,-0.469619f,0.191179f},
{-0.073446f,-0.469619f,0.220591f},{0.0735829f,-0.499031f,-0.220603f},{0.0735829f,-0.499031f,0.220574f},
{0.102995f,-0.499031f,-0.220603f},{0.102995f,-0.499031f,0.220574f},{0.102995f,-0.469619f,-0.220603f},
{0.102995f,-0.469619f,0.220574f},{0.0735829f,-0.469619f,-0.220603f},{0.0735829f,-0.469619f,0.220574f},
{-0.102995f,-0.499031f,-0.220574f},{-0.102995f,-0.499031f,0.220603f},{-0.0735829f,-0.499031f,-0.220574f},
{-0.0735829f,-0.499031f,0.220603f},{-0.0735829f,-0.469619f,-0.220574f},{-0.0735829f,-0.469619f,0.220603f},
{-0.102995f,-0.469619f,-0.220574f},{-0.102995f,-0.469619f,0.220603f},{-0.073446f,0.0634866f,0.191179f},
{-0.073446f,0.0634866f,0.220591f},{0.0736129f,0.0634866f,0.191179f},{0.0736129f,0.0634866f,0.220591f},
{0.0736129f,0.0928984f,0.191179f},{0.0736129f,0.0928984f,0.220591f},{-0.073446f,0.0928984f,0.191179f},
{-0.073446f,0.0928984f,0.220591f},{0.0735829f,0.0634866f,-0.220603f},{0.0735829f,0.0634866f,0.220574f},
{0.102995f,0.0634866f,-0.220603f},{0.102995f,0.0634866f,0.220574f},{0.102995f,0.0928984f,-0.220603f},
{0.102995f,0.0928984f,0.220574f},{0.0735829f,0.0928984f,-0.220603f},{0.0735829f,0.0928984f,0.220574f},
{-0.102995f,0.0634866f,-0.220574f},{-0.102995f,0.0634866f,0.220603f},{-0.0735829f,0.0634866f,-0.220574f},
{-0.0735829f,0.0634866f,0.220603f},{-0.0735829f,0.0928984f,-0.220574f},{-0.0735829f,0.0928984f,0.220603f},
{-0.102995f,0.0928984f,-0.220574f},{-0.102995f,0.0928984f,0.220603f}
};
static GLfloat normals [10][3] = {
{0.0f,-1.0f,0.0f},{0.707107f,0.0f,0.707107f},{1.0f,0.0f,0.0f},
{0.707107f,0.0f,-0.707107f},{0.0f,1.0f,0.0f},{-1.0f,0.0f,0.0f},
{-0.707107f,0.0f,0.707107f},{-0.707107f,0.0f,-0.707107f},{0.0f,0.0f,1.0f},
{0.0f,0.0f,-1.0f}
};
static GLfloat textures [4][2] = {
{1.0f,1.0f},{0.0f,1.0f},{0.0f,0.0f},
{1.0f,0.0f}
};
/*Material indicies*/
/*{material index,face count}*/
static int material_ref [1][2] = {
{0,84}
};
void MyMaterial(GLenum mode, GLfloat * f, GLfloat alpha)
{
	GLfloat d[4];
	d[0] = f[0];
	d[1] = f[1];
	d[2] = f[2];
	d[3] = alpha;
	glMaterialfv(GL_FRONT_AND_BACK, mode, d);
}

/*
 *  SelectMaterial uses OpenGL commands to define facet colors.
 *
 *  Returns:
 *    Nothing
 */

void SelectMaterial(int i)
{
//
// Define the reflective properties of the 3D Object faces.
//
	glEnd();
	GLfloat alpha = materials[i].alpha;
	MyMaterial(GL_AMBIENT, materials[i].ambient, alpha);
	MyMaterial(GL_DIFFUSE, materials[i].diffuse, alpha);
	MyMaterial(GL_SPECULAR, materials[i].specular, alpha);
	MyMaterial(GL_EMISSION, materials[i].emission, alpha);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, materials[i].phExp);
	glBegin(GL_TRIANGLES);

};

GLint Gen3DObjectList()
{
	int i;
	int j;

 GLint lid=glGenLists(1);
	int mcount=0;
	int mindex=0;
   glNewList(lid, GL_COMPILE);

    glBegin (GL_TRIANGLES);
      for(i=0;i<sizeof(face_indicies)/sizeof(face_indicies[0]);i++)
       {
	if (!mcount)
	{
		SelectMaterial(material_ref[mindex][0]);
		mcount = material_ref[mindex][1];
		mindex ++;
	}
	mcount --;
       for(j=0;j<3;j++)
        {
          int vi=face_indicies[i][j];
          int ni=face_indicies[i][j+3];//Normal index
          int ti=face_indicies[i][j+6];//Texture index
           glNormal3f (normals[ni][0],normals[ni][1],normals[ni][2]);
           glTexCoord2f(textures[ti][0],textures[ti][1]);
           glVertex3f (vertices[vi][0],vertices[vi][1],vertices[vi][2]);
        }
       }
    glEnd ();

   glEndList();
   return lid;
};
